// 公共日期格式化方法
const timeFormatting = function(timeDate) {
  if (typeof timeDate != "string") {
    var date = timeDate;
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    if (hours >= 0 && hours <= 9) {
      hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
      minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
      seconds = "0" + seconds;
    }
    date = month + "月" + strDate + "日 ";
    return date;
  } else {
    return timeDate;
  }
};

// 时间戳格式化
const TimestampFormat = function(TimestampFormat) {
  if (TimestampFormat < 10000) {
    return "住宿时长";
  } else {
    let total = TimestampFormat / 1000;
    let day = parseInt(total / (24 * 60 * 60)); //计算整数天数
    // let afterDay = total - day * 24 * 60 * 60; //取得算出天数后剩余的秒数
    let hour = parseInt(total / (60 * 60)); //计算整数小时数
    // let phour = parseInt(total / (60 * 60)); // 计算整小时数
    // let afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60; //取得算出小时数后剩余的秒数
    // let min = parseInt(afterHour / 60); //计算整数分
    // let afterMin = total - day*24*60*60 - hour*60*60 - min*60;//取得算出分后剩余的秒数
    if (hour >= 0 && hour < 24) {
      day + 1;
    } else if (hour >= 24 && hour < 48) {
      day + 2;
    } else if (hour >= 48 && hour < 72) {
      day + 3;
    }

    return day + "天";
  }
};

export default {
  timeFormatting,
  TimestampFormat
};
